import Base from 'models/base';

import moment from 'moment';
import SystemUtil from 'utils/systemUtil';

export default class GoodsDetail extends Base {
  constructor(history, systemTime) {
    super();

    let createTime = history.createTime;
    let time = moment(systemTime).diff(createTime, 'second');
    if (time <= 0) {
      time = 1;
    }
    let timeStr = '';
    if (time < 60) {
      timeStr = time + '秒前';
    } else if (time < 3600) {
      time = SystemUtil.floorValue(time / 60);
      timeStr = time + '分钟前';
    } else if (time < 24 * 3600) {
      time = SystemUtil.floorValue(time / 3600);
      timeStr = time + '小时前';
    } else {
      time = SystemUtil.floorValue(time / (24 * 3600));
      timeStr = time + '天前';
    }
    this.timeStr = timeStr;

    this.nickname = history.nickname;
    this.typeText = history.logType === 'v' ? '浏览' : '购买';
    this.id = SystemUtil.getId();
  }
}
